<template>
<div>
 <CityHeader></CityHeader>
 <CitySearch :cities='cities'></CitySearch>
 <CityList :hotCities='hotCities' :cities='cities' :letter="letter"></CityList>
 <CityAlphabet :cities='cities' @change="handleletterchange"></CityAlphabet>
</div>
</template>
<script>
import axios from 'axios'
import CityHeader from './components/Header'
import CitySearch from './components/Search'
import CityList from './components/List'
import CityAlphabet from './components/Alphabet'
export default {
  name: 'City',
  components: {
    CityHeader: CityHeader,
    CitySearch: CitySearch,
    CityList: CityList,
    CityAlphabet: CityAlphabet
  },
  data: function () {
    return {
      hotCities: [],
      cities: {},
      letter: ''
    }
  },
  methods: {
    getcityinfo () {
      axios.get('/api/city.json').then(this.getcityinfosucc)
    },
    getcityinfosucc (res) {
      console.log(res)
      if (res.data.data.hotCities) {
        this.hotCities = res.data.data.hotCities
      }
      if (res.data.data.cities) {
        this.cities = res.data.data.cities
      }
    },
    handleletterchange (str) {
      this.letter = str
      console.log(this.letter)
    }
  },
  mounted () {
    this.getcityinfo()
  }
}
</script>
<style lang="stylus" scoped>
</style>
